package com.example.mushroom.controller;

import com.example.mushroom.entity.Role;
import com.example.mushroom.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping
    public int insertRole(@RequestBody Role role) {
        return roleService.insertRole(role);
    }

    @GetMapping("/{id}")
    public Role selectRoleById(@PathVariable Integer id) {
        return roleService.selectRoleById(id);
    }

    @GetMapping
    public List<Role> selectAllRoles() {
        return roleService.selectAllRoles();
    }

    @PutMapping
    public int updateRole(@RequestBody Role role) {
        return roleService.updateRole(role);
    }

    @DeleteMapping("/{id}")
    public int deleteRoleById(@PathVariable Integer id) {
        return roleService.deleteRoleById(id);
    }

    @GetMapping("/page")
    public List<Role> selectRolesByPage(@RequestParam int offset, @RequestParam int limit) {
        return roleService.selectRolesByPage(offset, limit);
    }
}